package com.itxx.keyCase.test4;

import java.io.*;
import java.util.ArrayList;

//序列化Student对象练习题
public class Test4_1 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day12\\student.txt"));
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day12\\student.txt"));

        Student s1 = new Student("熊大", 13);
        Student s2 = new Student("熊二", 12);
        Student s3 = new Student("光土强", 23);
        Student s4 = new Student("李老板", 30);
        ArrayList<Student> studentlist = new ArrayList<>();
        studentlist.add(s1);
        studentlist.add(s2);
        studentlist.add(s3);
        studentlist.add(s4);
        oos.writeObject(studentlist);
        oos.flush();
        ArrayList<Student> list = (ArrayList<Student>) ois.readObject();
        System.out.println(list);


        //当读取到最后一个对象时  会抛出异常  解决  将对象条件进一个集合中
        oos.close();
        ois.close();


    }
}
